﻿using System;
using System.Web;
using System.Web.Caching;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Mtbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;
using HKEA.CMS.Core.BLL.Tbl;

namespace HKEA.CMS.Core.BLL.Mtbl
{
    public class mtblMembershipCategoryBLL
    {
        private ImtblMembershipCategory IDAL;

        public mtblMembershipCategoryBLL()
        {
            IDAL = DataAccess.CreateImtblMembershipCategory();
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static mtblMembershipCategoryBLL GetInstance()
        {
            return new mtblMembershipCategoryBLL();
        }

        public List<mtblMembershipCategory> GetAll()
        {
            List<mtblMembershipCategory> list = new List<mtblMembershipCategory>();
            try
            {
                list = IDAL.GetAll();
                return list;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public string GetMemCategoryByMemberUID(int memberUID)
        {
            string ret = string.Empty;
            List<mtblMembershipCategory> listMCategory = this.GetAll();            

            //列表最好加上缓存
            
            tblCust_Member entMember = tblCust_MemberBLL.GetInstance().GetENT(memberUID);
            
            if (entMember != null && listMCategory.Count() > 0)
            {
                int range_year = DateTime.Now.Year - entMember.JoinDate.Value.Year;
                foreach (mtblMembershipCategory ent in listMCategory)
                {
                    if (range_year >= ent.Lowers && range_year <= ent.Uppers)
                    {
                        ret = ent.CategoryName_Eng;
                        break;
                    }
                }
            }
            return ret;
        }
    }
}
